/*
 * Criado em 02/08/2008
 * 
 * Class needed for replaciong special chars when building a URL.
 * 
 * Credits: jack_-_ganzha - http://www.javafree.org/javabb/viewtopic.jbb?t=853035
 * 
 */
package com.apbetioli.mapr.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author alexandre
 */
public class SpecialCharFilter {

    private static String[] REPLACES;
    private static Pattern[] PATTERNS;
    
    static {

        REPLACES = new String[] {"a","e", "i", "o", "u", "c"};

        PATTERNS = new Pattern[REPLACES.length];

        PATTERNS[0] = Pattern.compile("[âãáàä]", Pattern.CASE_INSENSITIVE);
        PATTERNS[1] = Pattern.compile("[éèêë]" , Pattern.CASE_INSENSITIVE);
        PATTERNS[2] = Pattern.compile("[íìîï]" , Pattern.CASE_INSENSITIVE);
        PATTERNS[3] = Pattern.compile("[óòôõö]", Pattern.CASE_INSENSITIVE);
        PATTERNS[4] = Pattern.compile("[úùûü]" , Pattern.CASE_INSENSITIVE);
        PATTERNS[5] = Pattern.compile("[ç]"    , Pattern.CASE_INSENSITIVE);
    }

    public static String replaceSpecial(final String text) {

        String result = text;

        for (int i = 0; i < PATTERNS.length; i++) {

            Matcher matcher = PATTERNS[i].matcher(result);
            result = matcher.replaceAll(REPLACES[i]);

        }

        return result;

    }
}  
